set (PROJECT_OUTPUT_NAME MDevice.Checker)
project(${PROJECT_OUTPUT_NAME})

cmake_minimum_required( VERSION 2.6 )

set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_BUILD_TYPE Debug)

set(VER_MAJOR 0)
set(VER_MINOR 1)

execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR}/src autoIncVerConsole.exe
${VER_MAJOR}
${VER_MINOR}
${CMAKE_CURRENT_SOURCE_DIR})

INCLUDE(FindQt4)
find_package( Qt4 REQUIRED )
SET(QT_USE_QTSQL 1)
include( ${QT_USE_FILE})
add_definitions(-DUNICODE)

include_directories(
src
src/dialogs
src/service_classes
src/lib/qserialdevice/src/qserialdevice
src/lib/qserialdevice/src/qserialdeviceenumerator
${CMAKE_CURRENT_BINARY_DIR}
)

################################################################
# LIB
################################################################

set(lib_LIBS
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/qserialdevice/libqserialdevice.a
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/qserialdevice/libqserialdeviceenumerator.a
libsetupapi.a
uuid.a
advapi32.a
)

################################################################
# src
################################################################

set(src_SRC
src/MainWindow.cpp
src/main.cpp
src/dialogs/fmAbout.cpp
src/dialogs/fmHelp.cpp
share/res/RMD.rc
)

set(src_HEADERS
src/MainWindow.h
src/CONST.h
src/version.h
src/dialogs/fmAbout.h
src/dialogs/fmHelp.h
)

set(src_UI
src/MainWindow.ui
src/dialogs/fmAbout.ui
src/dialogs/fmHelp.ui
)

################################################################
# services classes
################################################################
#set(service_classes_SRC
#if(WIN32)
#src/service_classes/devicenotifier_win.cpp
#endif(WIN32)
#)

project(MDevice.Checker CXX)
message(STATUS "System: " ${CMAKE_SYSTEM_NAME} " " ${CMAKE_SYSTEM_VERSION})
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
if(MSVC)
message(STATUS "Compiler: MSVC, version: " ${MSVC_VERSION})
endif(MSVC)

if (CMAKE_COMPILER_IS_GNUCC)
    execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
                    OUTPUT_VARIABLE GCC_VERSION)
    string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
    list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
    list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)

    message(STATUS "Compiler: GNUCC, version: " ${GCC_MAJOR} "." ${GCC_MINOR})
endif()

if(BORLAND) 
message(STATUS "Compiler: BCC") 
endif(BORLAND) 
else(${CMAKE_SYSTEM_NAME} STREQUAL Linux) 
message(STATUS "Only GCC is supported on Linux")
endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows) 
message(STATUS "CMake generates " ${CMAKE_GENERATOR})

if(WIN32)
set(service_classes_SRC
src/service_classes/devicenotifier_win.cpp
src/service_classes/linusb_func.cpp
src/service_classes/opendevice.cpp
src/service_classes/MDeviceManager.cpp
src/service_classes/SerialPorts.cpp
src/service_classes/AutoRun.cpp
src/service_classes/appSettings.cpp
src/service_classes/auxiliaries_func.cpp
src/service_classes/TranslationLanguage.cpp
src/service_classes/SingleRun.cpp
src/service_classes/LTransliteration.cpp
)
else(WIN32)
set(service_classes_SRC
src/service_classes/devicenotifier_unix.cpp
src/service_classes/linusb_func.cpp
src/service_classes/opendevice.cpp
src/service_classes/MDeviceManager.cpp
src/service_classes/SerialPorts.cpp
src/service_classes/AutoRun.cpp
src/service_classes/appSettings.cpp
src/service_classes/auxiliaries_func.cpp
src/service_classes/TranslationLanguage.cpp
src/service_classes/SingleRun.cpp
src/service_classes/LTransliteration.cpp
)
endif(WIN32)

set(service_classes_HEADERS
src/service_classes/devicenotifier.h
src/service_classes/usbconfig.h
src/service_classes/usb.h
src/service_classes/requests.h
src/service_classes/opendevice.h
src/service_classes/libusb_func.h
src/service_classes/MDeviceManager.h
src/service_classes/SerialPorts.h
src/service_classes/AutoRun.h
src/service_classes/appSettings.h
src/service_classes/auxiliaries_func.h
src/service_classes/TranslationLanguage.h
src/service_classes/SingleRun.h
src/service_classes/LTransliteration.h
)

################################################################
# all
################################################################

set (
LIBRARIES
${lib_LIBS}
)

set(
SOURCES
${src_SRC}
${service_classes_SRC}
)

set(
HEADERS
${src_HEADERS}
${service_classes_HEADERS}
)

set(UI
${src_UI}
)

qt4_wrap_ui( UI_HEADERS ${UI} )
qt4_wrap_cpp( MOC_SOURCES ${HEADERS} )

set(
RESOURCES
share/res/application_res.qrc
)

qt4_add_resources( QRC_SOURCES ${RESOURCES} )

################################################################
################################################################

if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
	add_executable( ${PROJECT_OUTPUT_NAME} ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${UI_HEADERS})
else()
	add_executable( ${PROJECT_OUTPUT_NAME} WIN32 ${SOURCES} ${MOC_SOURCES} ${QRC_SOURCES} ${UI_HEADERS})
endif()

target_link_libraries( ${PROJECT_OUTPUT_NAME} ${LIBRARIES} ${QT_LIBRARIES} )
